<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <style>
    #tax_price,#insurance_fee_cart,.order_total_list ul:first-child li:nth-child(2n),.order_total_list ul:first-child li:nth-child(4n){
      display: none !important;
    }
    #custom-list{
      margin-top: 10px;
    }
  </style>
  <script>
    document.addEventListener("DOMContentLoaded", function () {
      $(".order_total_list").append(`<ul id="custom-list"></ul>`)
      var exh = {
        AC: 0.2,
        AL: 0.2,
        AP: 0.18,
        AM: 0.17,
        BA: 0.2,
        CE: 0.2,
        DF: 0.17,
        ES: 0.17,
        GO: 0.17,
        MA: 0.17,
        MT: 0.17,
        MS: 0.17,
        MG: 0.17,
        PR: 0.17,
        PB: 0.2,
        PA: 0.17,
        PE: 0.17,
        PI: 0.2,
        RN: 0.2,
        RS: 0.17,
        RJ: 0.17,
        RO: 0.17,
        RR: 0.2,
        SC: 0.17,
        SE: 0.2,
        SP: 0.17,
        TO: 0.17
      }
      function getExchange() {
        if (oemcart_current_template === "order_payment_gateway") {
          return exh[_GET_C_SETTING_("order").shipping_address.province_code]
        }
        var province = $('select[name="province"]').val()
        if (!province) {
          return 0
        }
        return exh[province]
      }
      function setTariffPrice() {
        if (!order_price_detail.insurance_price) {
          return 0
        }
        var totalPrice = order_price_detail.product_price + order_price_detail.shipping_price;
        // var exchange_rate =  parseFloat(_GET_C_SETTING_('order_currency').exchange_rate)
        if (totalPrice <= (50 / 0.1828)) {
          return (totalPrice) * 0.2;
        }
        return (totalPrice) * 0.6 - (20 / 0.1828);
      }
      function setICMSprice() {
        if (!order_price_detail.tax_price) {
          return 0
        }
        //  1 代表(1-ICMS对应州税率 2代表xICMS对应州税至
        var ICMSprice = (order_price_detail.product_price + order_price_detail.shipping_price + setTariffPrice()) / (1 - getExchange()) * getExchange()
        return ICMSprice
      }

      function setOfferHtml() {
        var tariffPrice = setTariffPrice();
        var ICMSprice = setICMSprice();
        var beforePrice = order_price_detail.tax_price + order_price_detail.insurance_price;
        var afterPrice = ICMSprice + tariffPrice;
        var price = beforePrice - afterPrice;
        var htmlStr = [];
        if (tariffPrice) {
          htmlStr.push(`<li ><div class="name">lmposto de Importagäo</div><div class="value">${Number(tariffPrice).orderCurrency()}</div></li>`)
        }
        if (ICMSprice) {
          htmlStr.push(`<li ><div class="name">ICMS</div><div class="value">${Number(ICMSprice).orderCurrency()}</div></li>`)
        }
        if (price) {
          htmlStr.push(`<li id="offer-price"><div class="name">VIP Ofertas</div><div class="value">${Number(price).orderCurrency()}</div></li>`)
        }
        $("#custom-list").html(htmlStr.join(''));
      }

      useOrderPriceEffect(['shipping_price'], function () {
        setTimeout(() => {
          setOfferHtml()
        }, 0)
      })
      if (oemcart_current_template === "order_payment_gateway") {
        setOfferHtml()
      }
    })
  </script>
</body>

</html>